package com.domcer.ultra.menu.domain;

import lombok.*;
import org.bukkit.configuration.ConfigurationSection;

import java.util.List;

/**
 * @Author hang.wang
 * @Date 2025/1/30 22:54
 */
@Getter
@Setter
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class MenuSettingsDomain {
    private String name;
    private int rows;
    private List<String> commands;
    private int refresh;
    private List<String> openActions;
    private List<String> openRequires;
    private MenuSettingsOpenItemDomain openItem;

    public static MenuSettingsDomain assemble(ConfigurationSection section) {
        if (section == null) {
            return null;
        }

        return MenuSettingsDomain.builder()
                .name(section.getString("name", "Default Name"))
                .rows(section.getInt("rows", 3))
                .commands(section.getStringList("commands"))
                .refresh(section.getInt("refresh", 5))
                .openActions(section.getStringList("open-actions"))
                .openRequires(section.getStringList("open-requires"))
                .openItem(MenuSettingsOpenItemDomain.assemble(section.getConfigurationSection("open-item")))
                .build();
    }
}
